<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <input type="text" id="inputId">
    <button onclick="guess()">猜</button>
    <span id="resultId"></span>

    <script>
        var random = parseInt(Math.random() * 100 + 1);
        console.log(random);

        function guess() {
            var guess = document.getElementById('inputId').value;
            var resultObj = document.getElementById('resultId');
            if (guess == ''){
                resultObj.innerText = '不能为空';
                return;
            }
            if (isNaN(guess)) {
                resultObj.innerText = '请输入一个数字';
                return;
            }

            if (guess > random) {
                resultObj.innerText = '太大了';
            } else if (guess < random) {
                resultObj.innerText = '太小了';
            } else {
                resultObj.innerText = '猜对了';
            }
        }
    </script>
</body>
</html>